package com.company.JUC.AQS.Semaphore;

import java.util.concurrent.Semaphore;

/**
 * @Classname MyCircularQueue
 * @Description TODO
 * @Date 2021/8/18 18:49
 * @Created by ylr
 */
public class Main {
    public static void main(String[] args) {
        Semaphore semaphore = new Semaphore(3);
        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                try {
                    semaphore.acquire();
                    System.out.println(Thread.currentThread().getName()+ " 拿到了信号量!");
                    Thread.sleep(3000);
                    System.out.println(Thread.currentThread().getName()+ "释放了信号量");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    semaphore.release();
                }
            },String.valueOf(i)).start();
        }
    }
}
